<?php
namespace Admin\Controller;
use Think\Model;

/**
 * 店铺订单统计
 * @package Admin\Controller
 */
class StoreOrderSalesController extends BaseController {
    public function __construct()
    {
        parent::__construct();
        $this->local_id = session('userInfo')['local_id'];
    }
    /**
     * 订单统计
     */
    public function orderSale(){

       //支付流水统计
        $res =  M('statistical_local_order')->where(['local_id'=>$this->local_id])->find();
        $this->assign('order_result',$res);

        //订单查询
        $b_time = $_GET['start_time'];
        $end_time = $_GET['end_time'];
        if($_GET['start_time'] != '开始时间' && $_GET['end_time'] != '结束时间' && !empty($_GET['end_time']) && !empty($_GET['start_time']) ){
            $_GET['p'] = 1;
            $where = "local_id = ".$this->local_id. " and time >= '". $b_time . "' and time <= '".$end_time."'" ;
        }else{
            $where = "local_id = ".$this->local_id;
        }
        if($_GET['p']>0){
            $limit = ' limit '.(($_GET['p'] - 1)*15).','.'15';
        }else{
            $limit = ' limit 0,15';
        }
        $res_search =  M()->query("select * from sdb_statistical_order_day  where ".$where.' order by time desc'.$limit);


        $count_list = M()->query("select * from sdb_statistical_order_day  where ".$where);
        $count = count($count_list);
        $Page = new \Think\Page($count, 15,$_GET);// 实例化分页类 传入总记录数和每页显示的记录数
        $show = $Page->show();// 分页显示输出

        $this->assign('page',$show);
        $this->assign('order_result_search',$res_search);
        $this->display('SaleCount/orderSale');
    }


}